package com.jrx.anytxn.transaction.mapper.ext;

import com.jrx.anytxn.transaction.entity.AmInterestAccrualInfo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * @author haopu.zheng
 * 累计账户mapper扩展
 * date: 2019/8/7
 **/
public interface ExtAmInterestAccrualInfoMapper {

    /**
     * 根据贷款ID、状态、类型、期数、客户号获取累计账户信息
     *
     * @param loanId        贷款id
     * @param statusList    状态list
     * @param typeList      类型list
     * @param billingTenors 期数list
     * @param customerId    客户id
     * @param tenantId      租户id
     * @return java.util.List<com.jrx.anytxn.transaction.entity.AmInterestAccrualInfo>
     * @author : zhenghaopu
     * date: 2019/9/25
     */
    List<AmInterestAccrualInfo> selectByStatusAndType(@Param(value = "loanId") String loanId,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param("tenantId") String tenantId,
                                                      @Param(value = "statusList") List<String> statusList,
                                                      @Param(value = "typeList") List<String> typeList,
                                                      @Param(value = "billingTenors") List<Integer> billingTenors);


    /**
     * 根据状态查询累计账户   order by id asc  计息批量使用
     *
     * @param status 状态
     */
    List<AmInterestAccrualInfo> selectByStatus(@Param(value = "status") String status);


    /**
     * 批量插入累计账户信息
     *
     * @param amInterestAccrualInfos
     * @param amInterestAccrualInfos 累计账户信息
     * @return int
     * @author zhenghaopu
     * date: 2019/9/9 11:29
     */
    int batchInsertInterestAccrualInfo(List<AmInterestAccrualInfo> amInterestAccrualInfos);

    /**
     * 根据条件查询累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param billingTenor
     * @param status
     * @return
     */
    List<AmInterestAccrualInfo> selectAccuAcct(@Param(value = "loanId") String loanId,
                                               @Param(value = "customerId") String customerId,
                                               @Param(value = "tenantId") String tenantId,
                                               @Param(value = "type") String type,
                                               @Param(value = "billingTenor") Integer billingTenor,
                                               @Param(value = "status") String status);

    /**
     * 批量更新累计账户信息（联机可用）
     *
     * @param amInterestAccrualInfos
     * @return int
     * @author jing.xiaoyu
     * date: 2019/10/13 11:29
     */
    int batchUpdateInterestAccrualInfo(List<AmInterestAccrualInfo> amInterestAccrualInfos);

    /**
     * 批量更新累计账户信息（批量可用）
     *
     * @param amInterestAccrualInfos
     * @return int
     * @author jing.xiaoyu
     * date: 2019/10/13 11:29
     */
    int batchUpdateInterestAccrualInfoForBatch(List<AmInterestAccrualInfo> amInterestAccrualInfos);

    /**
     * 根据主键及客戶id与租户id修改累计账户信息
     *
     * @param amInterestAccrualInfos 要修改累计账户信息
     * @return
     */
    int updateByIdAndCustomerIdAndTenantId(AmInterestAccrualInfo amInterestAccrualInfos);

    /**
     * 根据条件查询累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param typeList
     * @param statusList
     * @return
     */
    List<AmInterestAccrualInfo> selectAllAccuAcct(@Param(value = "loanId") String loanId,
                                                  @Param(value = "customerId") String customerId,
                                                  @Param(value = "tenantId") String tenantId,
                                                  @Param(value = "typeList") List<String> typeList,
                                                  @Param(value = "statusList") List<String> statusList);

    /**
     * 查询累计未抛利息
     *
     * @param loanId
     * @param accountStatus
     * @return
     */
    List<AmInterestAccrualInfo> selectForUpdateUncastIntr(@Param(value = "loanId") String loanId,
                                                          @Param(value = "accountStatus") String accountStatus);

    /**
     * 根据条件查询累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param billingTenor
     * @param status
     * @return
     */
    List<AmInterestAccrualInfo> selectAccuAcctList(@Param(value = "loanId") String loanId,
                                                   @Param(value = "customerId") String customerId,
                                                   @Param(value = "tenantId") String tenantId,
                                                   @Param(value = "status") String status,
                                                   @Param(value = "billingTenor") Integer billingTenor);

    /**
     * 根据更新日期查询账户累计信息表
     *
     * @param startTime
     * @param endTime
     * @return
     */

    List<AmInterestAccrualInfo> selectByUpdateTimeSelective(@Param(value = "startTime") String startTime,
                                                            @Param("endTime") String endTime);

    /**
     * 根据条件查询累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param type
     * @return
     */
    List<AmInterestAccrualInfo> selectAllIntr(@Param(value = "loanId") String loanId,
                                              @Param(value = "customerId") String customerId,
                                              @Param(value = "tenantId") String tenantId,
                                              @Param(value = "type") String type);

    /**
     * 正在计息的累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param type
     * @param billingTenor
     * @param status
     * @return
     */
    AmInterestAccrualInfo selectAccuAcctNotStopping(@Param(value = "loanId") String loanId,
                                                    @Param(value = "customerId") String customerId,
                                                    @Param(value = "tenantId") String tenantId,
                                                    @Param(value = "type") String type,
                                                    @Param(value = "billingTenor") Integer billingTenor,
                                                    @Param(value = "status") String status);

    /**
     * 根据条件查询累计账户
     *
     * @param loanId
     * @param customerId
     * @param tenantId
     * @param type
     * @param status
     * @param stopFlag
     * @return
     */
    List<AmInterestAccrualInfo> selectAllStopAccuAcct(@Param(value = "loanId") String loanId,
                                                      @Param(value = "customerId") String customerId,
                                                      @Param(value = "tenantId") String tenantId,
                                                      @Param(value = "type") String type,
                                                      @Param(value = "status") String status,
                                                      @Param(value = "stopFlag") String stopFlag);

    /**
     * 查询客户下所有正常计提的累计账户
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmInterestAccrualInfo> selectByCust(@Param(value = "customerId") String customerId,
                                             @Param(value = "tenantId") String tenantId,
                                             @Param(value = "statusList") List<String> statusList);

    /**
     * 查询客户下所有正常计提的累计账户
     *
     * @param customerId
     * @param tenantId
     * @return
     */
    List<AmInterestAccrualInfo> selectByCustWithProducts(@Param(value = "customerId") String customerId,
                                                         @Param(value = "tenantId") String tenantId,
                                                         @Param(value = "statusList") List<String> statusList,
                                                         @Param("productIds") List<String> productIds);

    /**
     * 根据账户id查询利息累计账户
     *
     * @param accountId
     * @param tenantId
     * @return AmInterestAccrualInfo
     */
    AmInterestAccrualInfo selectByAccountId(@Param(value = "accountId") String accountId, @Param(value = "tenantId") String tenantId);

    /**
     *
     * @param status
     * @return
     */
    List<AmInterestAccrualInfo> selectByAccountTypeAndStatus(@Param(value = "accountType") String accountType,@Param(value = "accountStatus") String status
            ,@Param(value = "nextDay") Date nextDay);

    /**
     * 按订单查询已经累计利息
     * @param loanId
     * @param customerId
     * @param tenantId
     * @return
     */
    BigDecimal sumInterAccrualInfo(@Param(value = "loanId") String loanId,
                                   @Param(value = "customerId") String customerId,
                                   @Param(value = "tenantId") String tenantId);
}